//
//  SearchTableViewController.swift
//  HDSearchDemo
//
//  Created by HD-XXZQ-iMac on 2018/1/31.
//  Copyright © 2018年 HD-XXZQ-iMac. All rights reserved.
//

import UIKit

class SearchTableViewController: UITableViewController {

    var resultDataArr = [WPFPerson]()
    
    override init(style: UITableViewStyle) {
        super.init(style: style)
        
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.automaticallyAdjustsScrollViewInsets = false
    }

    
    // MARK: - Table view data source

    override func numberOfSections(in tableView: UITableView) -> Int {
        // #warning Incomplete implementation, return the number of sections
        return 1
    }

    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        // #warning Incomplete implementation, return the number of rows
        return self.resultDataArr.count
    }

    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell: UITableViewCell? = tableView.dequeueReusableCell(withIdentifier: "cell")
        let person: WPFPerson? = self.resultDataArr[indexPath.row]
        // 设置关键字高亮
        let attributedString = NSMutableAttributedString(string: person?.name ?? "")
        attributedString.addAttributes([NSAttributedStringKey.foregroundColor: UIColor(red: 0, green: 131 / 255.0, blue: 0, alpha: 1.0)], range: person?.textRange ?? NSRange())
        cell?.textLabel?.attributedText = attributedString
        return cell!
    }
    
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
    }                                  
}
